package com.gdth.bank.model;

import java.util.List;

import rx.Observable;
import rx.Subscriber;

import com.gdth.bank.BankApplication;
import com.gdth.database.bean.TAppFjxxb;
import com.gdth.database.bean.TAppFjxxbDao;

import org.greenrobot.greendao.query.QueryBuilder;


public class DzCpKhXxFjModel {
	public Observable<TAppFjxxb> saveDzcpkhxxfj(final TAppFjxxb mTAppFjxxb){
		return Observable.create(new Observable.OnSubscribe<TAppFjxxb>() {

			@Override
			public void call(Subscriber<? super TAppFjxxb> arg0) {
				// TODO Auto-generated method stub
				TAppFjxxbDao dao = BankApplication.getDaoSession().getTAppFjxxbDao();
				Long id=mTAppFjxxb.getId();
				String lj=mTAppFjxxb.getAppdz();
				String fjuuid=mTAppFjxxb.getUuid();
				if (id != null){
				   dao.update(mTAppFjxxb);
				}else{
				   dao.insert(mTAppFjxxb);
				}
			}
		});
	}
	public Observable<List<TAppFjxxb>> getDzcpkhxxfl(final String uuid){
		return Observable.create(new Observable.OnSubscribe<List<TAppFjxxb>>() {

			@Override
			public void call(Subscriber<? super List<TAppFjxxb>> arg0) {
				// TODO Auto-generated method stub
				TAppFjxxbDao dao = BankApplication.getDaoSession().getTAppFjxxbDao();
				QueryBuilder<TAppFjxxb> qb = dao.queryBuilder();
				if (uuid != null && !uuid.equals(""))
					qb.where(TAppFjxxbDao.Properties.Wybs.eq(uuid));
				
				List<TAppFjxxb> mList = qb.list();
				if (mList == null){
					arg0.onError(null);
				} else {
					arg0.onNext(mList);
					arg0.onCompleted();
				}
			 
			}
		});
	}
	
}
